package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;
// default package

/**
 * CalendarDayDTO entity. @author MyEclipse Persistence Tools
 */

public class CSVCalendarDayDTO extends java.lang.Object implements IsSerializable, ICSVDTO {


    // Fields    

     private long id;
     private String semester;
     private String dayLabel;
     private Long displayOrder;
     private String sunday;

     
     private boolean highlighted;
     
     public static final int SORT_CONST__DAY_LABEL = 0;
     public static final int SORT_CONST__DISPLAY_ORDER = 1;
     public static final int SORT_CONST__SUNDAY = 2;
     public static final int SORT_CONST__SEMESTER = 3;
     
     public static final int SORT_CONST__ID = 4;

    // Constructors

    /** default constructor */
    public CSVCalendarDayDTO() {
    }

    
    /** full constructor */
    public CSVCalendarDayDTO(long id, String semester, String dayLabel, Long displayOrder, String sunday) {
    	this.id = id;
        this.semester = semester;
        this.dayLabel = dayLabel;
        this.displayOrder = displayOrder;
        this.sunday = sunday;
    }


	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}


	

	public String getSemester() {
		return semester;
	}


	public void setSemester(String semester) {
		this.semester = semester;
	}


	public String getDayLabel() {
		return dayLabel;
	}


	public void setDayLabel(String dayLabel) {
		this.dayLabel = dayLabel;
	}


	

	public Long getDisplayOrder() {
		return displayOrder;
	}


	public void setDisplayOrder(Long displayOrder) {
		this.displayOrder = displayOrder;
	}


	public String getSunday() {
		return sunday;
	}


	public void setSunday(String sunday) {
		this.sunday = sunday;
	}


	public String toString() {
		String r;
		r = dayLabel + ", order: " + displayOrder + ", semestr: " + semester + ", sunday: " + sunday;
		return r;
	}
	
	public String toLabel() {
		String r = "[" + getDisplayOrder() + "] " +
			getDayLabel();
		return r;
	}


	public boolean isHighlighted() {
		return highlighted;
	}


	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}

	
	@SuppressWarnings("unchecked")
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

//			    final int BEFORE = -1;
			    final int EQUAL = 0;
//			    final int AFTER = 1;
			    
			    CSVCalendarDayDTO obj1;
			    CSVCalendarDayDTO obj2;
			    if (o1 instanceof CSVCalendarDayDTO && o2 instanceof CSVCalendarDayDTO) {

					obj1 = (CSVCalendarDayDTO) o1;
					obj2 = (CSVCalendarDayDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__DAY_LABEL) {
						return obj1.getDayLabel().compareTo(obj2.getDayLabel());
					} else if (colIndex == SORT_CONST__DISPLAY_ORDER) {
						return obj1.getDisplayOrder().compareTo(obj2.getDisplayOrder());
					} else if (colIndex == SORT_CONST__SEMESTER) {
						return obj1.getSemester().compareTo(obj2.getSemester());
					} else if (colIndex == SORT_CONST__SUNDAY) {
						return obj1.getSunday().compareTo(obj2.getSunday());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}
	
	

	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__DAY_LABEL) {
			return "" + getDayLabel();
		} else if (col == SORT_CONST__DISPLAY_ORDER) {
			return "" + getDisplayOrder();
		} else if (col == SORT_CONST__SUNDAY) {
			return "" + getSunday();
		} else if (col == SORT_CONST__SEMESTER) {
			return "" + getSemester();
		}
		return "no field";
	}



	


}